package level

import (
	"github.com/name5566/leaf/log"
	"server/cfg"
)

// 获取玩家关卡信息
func GetPlayerLevelInfo(userID string) (UserLevelInfo, error) {
	logic := NewLevelLogic()
	return logic.LevelInfo(userID)
}

func IncreaseLevelProgress(userID string, totalTalentAbility int) error {
	logic := NewLevelLogic()
	return logic.IncreaseLevelProgress(userID, totalTalentAbility)
}

// 关底战逻辑
func BossBattle(userID string, totalTalentAbility int) (bool, error) {
	// 获取玩家关卡信息
	logic := NewLevelLogic()
	return logic.BossBattle(userID, totalTalentAbility)
}

func GuanKaPeiXunShouRu(uid string) float32 {
	logic := NewLevelLogic()
	return logic.GuanKaPeiXunShouRu(uid)
}

func ZhaoGong(uid string, cardId int64) (map[string]interface{}, error) {
	logic := NewLevelLogic()
	return logic.ZhaoGong(uid, cardId)
}
func PeiXun(uid string, cardId int64) (map[string]interface{}, error) {
	logic := NewLevelLogic()
	return logic.PeiXun(uid, cardId)
}

// 关卡直接加成
func levelZhuanSuZhiJieJiaCheng(uid string) int {
	var zhiJieJiaCheng int
	playerInfo, err := GetPlayerLevelInfo(uid)
	if err != nil {
		log.Error("用户id%s获取用书数据失败错误信息是%v", uid, err)
		return 0
	}

	for cardId, levelPeiXunCardsInfo := range playerInfo.WanChengPeiXunGuanKaCardIds {
		config := cfg.ConfigData.TbGuanQia.Get(int32(cardId))
		peiXunCardIdsNum := len(levelPeiXunCardsInfo)
		zhiJieJiaCheng += int(config.EarnAdd) * peiXunCardIdsNum
	}
	return zhiJieJiaCheng
}

// 关卡比例加成
func levelZhuanSuBiLiJiaCheng(uid string) int {
	var zhiJieJiaCheng int
	playerInfo, err := GetPlayerLevelInfo(uid)
	if err != nil {
		log.Error("用户id%s获取用书数据失败错误信息是%v", uid, err)
		return 0
	}

	for cardId, levelPeiXunCardsInfo := range playerInfo.WanChengPeiXunGuanKaCardIds {
		config := cfg.ConfigData.TbGuanQia.Get(int32(cardId))
		peiXunCardIdsNum := len(levelPeiXunCardsInfo)
		zhiJieJiaCheng += int(config.EarnAdd) * peiXunCardIdsNum
	}
	return zhiJieJiaCheng
}
